import { ElMessage } from 'element-plus'
import 'element-plus/theme-chalk/el-message.css'
import { Ls, bus } from '@/utils/common'
import store from '@/store'

export const globalPlugin = {
  install (app, options) {
    app.config.globalProperties.$message = ElMessage
    app.config.globalProperties.$ls = Ls
    app.config.globalProperties.$bus = bus

    app.directive('authority', (el, binding) => {
      // mounted 和 updated的时候执行
      const { arg } = binding
      const { superadmin } = binding.modifiers
      const { role, adminname } = store.state.authority
      if (adminname !== 'admin' && superadmin && role !== 2) {
        switch (arg) {
          case 'remove':
            el.remove()
            break;
          case 'disabled':
            el.disabled = true
            el.className += ' is-disabled '
            break;
          default:
            break;
        }
      }
    })
  }
}
